package com.itheima.reggie_auto.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.reggie_auto.entity.DishFlavor;
import com.itheima.reggie_auto.mapper.DishFlavorMapper;
import com.itheima.reggie_auto.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DishFlavorServiceImpl implements DishFlavorService {
    @Autowired
    private DishFlavorMapper dishFlavorMapper;

    /**
     * 保存集合数据
     * @param list
     */
    public void saveBatch(List<DishFlavor> list){
        list.forEach(item->{
            dishFlavorMapper.insert(item);
        });
    }

    @Override
    public List<DishFlavor> getByDishId(Long id) {
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId,id);
        List<DishFlavor> dishFlavors = dishFlavorMapper.selectList(lqw);
        return dishFlavors;
    }

    @Override
    public void deleteByDishId(Long dishId) {
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId,dishId);
        dishFlavorMapper.delete(lqw);
    }

}
